package com.marvels.financial.loan.service.impl;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.marvels.common.utils.CommonProperties;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.loan.dao.OverDueManageMapper;
import com.marvels.financial.loan.service.OverDueManageService;

@Service
public class OverDueManageServiceImpl implements OverDueManageService {
	@Autowired
	private OverDueManageMapper overDueManageMapper;
	@Override
	@Transactional
	public void OverTenorManage(Date date) {//date为当前时间
		MarvelsLogUtil.getInstance().info("the OverDueManage task start -----------------------------------");
		//当配置为分期时，单独计算应还款日 
		if(StringUtils.equalsIgnoreCase("Y", CommonProperties.getNewRepaymentFlag())) {
			overDueManageMapper.newInsertMpOverdueManageTmp(date);
		}else {
			overDueManageMapper.insertMpOverdueManageTmp(date);//把逾期的数据写入临时表中
		}
		
		MarvelsLogUtil.getInstance().info("the insertMpOverdueManageTmp completed -----------------------------------");
		
		MarvelsLogUtil.getInstance().info("the updateContract start -----------------------------------");
		overDueManageMapper.updateContract(date);//跟新合同
		MarvelsLogUtil.getInstance().info("the updateContract end -----------------------------------");
		
		MarvelsLogUtil.getInstance().info("the insertMonetaryTxnInfoFee1 start -----------------------------------");
		overDueManageMapper.insertMonetaryTxnInfoFee1(date);//插入金融表违约金
		MarvelsLogUtil.getInstance().info("the insertMonetaryTxnInfoFee1 end -----------------------------------");
		
		MarvelsLogUtil.getInstance().info("the insertMonetaryTxnInfoFee1 start -----------------------------------");
		overDueManageMapper.insertMonetaryTxnInfoFee2(date);//插入金融表滞纳金
		MarvelsLogUtil.getInstance().info("the insertMonetaryTxnInfoFee1 end -----------------------------------");
		
		MarvelsLogUtil.getInstance().info("the updateAccount start -----------------------------------");
		overDueManageMapper.updateAccount(date);//更新账户表
		MarvelsLogUtil.getInstance().info("the updateAccount end -----------------------------------");
		
		MarvelsLogUtil.getInstance().info("the updateLoanPlan start -----------------------------------");
		overDueManageMapper.updateLoanPlan(date);//更新还款计划
		MarvelsLogUtil.getInstance().info("the updateLoanPlan end -----------------------------------");
//		String a = null;
//		a.equals("");
	}

}